<template>
    <!-- 修改用户 -->
    <el-dialog
    title="修改用户"
    :visible.sync="visible"
    width="50%">
      <!-- 内容主体区域 -->
      <el-form :model="updateUserForm" :rules="updateUserRule"
      ref="updateUserFormRef" label-width="70px">
        <el-form-item label="学号" prop="username">
          <el-input v-model="updateUserForm.username"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="fullname">
          <el-input v-model="updateUserForm.fullname"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="updateUserForm.mobile"></el-input>
        </el-form-item>
        <el-form-item label="用户类别" prop="role">
          <el-input v-model="updateUserForm.role"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部按钮区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
</template>
<script>
export default {
  data () {
    return {
      visible: false,
      updateUserForm: {
        username: '',
        fullname: '',
        mobile: '',
        role: ''
      },
      updateUserRule: {
        username: [{ required: true, message: '请输入学号', trigger: 'blur' },
          { min: 3, max: 20, message: '长度不符合要求' }],
        fullname: [{ required: true, message: '请输入姓名', trigger: 'blur' },
          { min: 3, max: 20, message: '长度不符合要求' }],
        mobile: [{ required: true, message: '请输入手机号', trigger: 'blur' },
          { min: 3, max: 20, message: '长度不符合要求' }],
        role: [{ required: true, message: '请选择角色类型', trigger: 'blur' },
          { min: 3, max: 20, message: '长度不符合要求' }]
      }
    }
  },
  methods: {
    async show (id) {
      const { data } = await this.$http.get(`/api/user/${id}`)
      if (!data || !data.success) return this.$message.error('获取用户列表失败')
      console.log(data)
      this.users = data.users
      this.total = data.total
      this.visible = true
    },
    submit () {
      this.$refs.addUserFormRef.validate(async valid => {
        if (!valid) return
        console.log(this.addUserForm)
      })
      this.visible = false
    },
    cancel () {
      this.visible = false
    }
  }
}
</script>
